home *** CD-ROM | disk | FTP | other *** search
/ Shareware Universe - The Gold Collection / Shareware Universe The Gold Collection.iso / ray / winmorph / winmorph.go < prev    next >
Text File  |  1996-04-19  |  10KB  |  334 lines

  1. WMORPH - 2-D Morphing Program
  2.  
  3.                Version 1.0  May 21, 1993
  4.  
  5.              Lam Ka Po (cs_lamkp@stu.ust.hk)
  6.                Wong Wing Kin (cs_wwkin@stu.ust.hk)
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16. Objective
  17.  
  18.     This program WMORPH is a self-proposed project in our Computer
  19. Graphics course.  The aim of the project is to build a 2-D Morphing system
  20. running on PC.  User can input two 320x200 256-color GIF images files
  21. and specify corresponding points on the two images.  The system will
  22. produce a series of intermediate images showing the transition from the
  23. original image to the desired image.  The intermediate images are
  24. stored as 320x200 256-color GIF images file.
  25.  
  26.  
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  
  38.  
  39. 2-D Morphing
  40.     
  41.     Most of the techniques for 2-D morphing come from digital image
  42. warping; a growing branch of image processing.  Digital image warping deals
  43. with the geometric transformation of digital images, redefining the spatial
  44. relationship between points in an image.  One of the most common applications
  45. for image warping is texture mapping, a technique that is central to morphing.  To do a
  46. morph, the animator needs to define a correspondence between the initial and
  47. final images.  This can be done using points, triangles or meshes.  Once the
  48. relationship has been defined, the textures in the images are blended from
  49. the initial image to the final image to produce the morphing sequence.
  50.  
  51.     The method of subdividing the images varies between different morphing 
  52. programs.  The one used in this project defines common points in the two
  53. images.  For a human face, these points could include the eyes, eyebrows,
  54. nose and mouth.  Triangles are built from these points to create corresponding
  55. areas on the images.  One of the most popular triangulation algorithms,
  56. Delaunay triangulation is used in this program.  Delaunay's algorithm
  57. maximizes the angles within each triangle and minimizes the lengths of the
  58. sides.
  59.  
  60.     After subdividing the images, the transformation from the source to the 
  61. destination begins.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.  
  82.  
  83.  
  84.  
  85. Project Description
  86.     
  87. A. Operating Environment
  88.  
  89. 1.      DOS 5.0 or above
  90. 1.      80386 or above
  91. 2.      VGA 320x200 256 color
  92. 3.      Mouse & MS Mouse Driver ver 8.0 or above
  93. 4.      At least 5M hard disk space for output files
  94. 5.      At least 300K conventional memory
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108. B. Program Description
  109.  
  110. 1. Menu Display
  111.  
  112. a. Input image files
  113.  
  114.     Two buttons named "Source" and "Target" are used to 
  115. input images file.  When the button "Source" is clicked, a dialog box
  116. would appear and prompt the user to input the source file.  When 
  117. this file is successfully loaded, the button name is replaced by the 
  118. source file name and the image would appear on the left window of the
  119. menu.  Similarly, the destination file can be loaded using the "Target"
  120. button.  The destination image would appear on the right window of
  121. the menu.
  122.  
  123. b. image Movement
  124.     
  125.     As the window size is smaller than the image size,
  126. clipping is employed to display only a portion of the image in the
  127. screen.  In order to scroll to the other part of the images, four
  128. buttons can be used.  These four buttons placed at the lower left 
  129. part of the menu.  The four direction buttons represent the 
  130. movement in the four directions.  Two speed can be used to move.  
  131. When the center part of button is clicked, the movement is slow.  
  132. However, when the tip of the direction sign is clicked, the 
  133. movement is about five times the slower one. 
  134.  
  135. c. Mouse Pointer
  136.  
  137.     A mouse pointer can be seen in the menu.  It is used not 
  138. only to click the menu button, but also for point selection.  When
  139. click the mouse on the images, a white spot appeared indicating
  140. that that point is chosen.
  141.  
  142. d. Add Button
  143.  
  144.     The Add button is used to confirm the points selected on the
  145. images.  After the selecting the two points on each image, the user
  146. should then click the Add button to confirm that this point is to be 
  147. added.  After clicking this button, the point would be read and 
  148. triangles are formed on the images.
  149.  
  150. e. Morph Button
  151.  
  152.     The button Morph is used to start morphing.  When this button
  153. is clicked, a dialog box would ask the user to input the file name.
  154. It should be not more than five characters since another three digits
  155. would added to the end of the file name to indicate the series of images.
  156. Then, another dialog box would prompt the user to input the number of
  157. intermediate steps required.
  158.  
  159. f. Exit Button
  160.     This button is clicked when the user would like to 
  161. terminate the execution of the program.
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177. C. Program Processing
  178.  
  179. 1. Delaunay Triangulation 
  180.  
  181.     The system use the "On-line Delaunay Triangulation" 
  182. algorithm to link up all inputted points on the source and destination
  183. images.  On-line algorithm is used to give user a look
  184. on the triangulation before input another points.
  185.  
  186.     The employ of the optimal triangulation algorithm is to 
  187. avoid generating triangles with sharp angles and long edges.  This 
  188. is important for image processing applications as it ensures that 
  189. only nearby data points will be used in the surface patch 
  190. computations that will follow.
  191.  
  192.     Initially, the four corners are pre-inputted as the first four 
  193. points.  Therefore, a diagonal line is seen on each images after
  194. loading since two triangles are formed by four corner points.  In 
  195. addition, no points can be added on the four boundary edges of 
  196. each images.
  197.  
  198. 2. Bresenham Scan Converting Line Algorithm
  199.  
  200.     Bresenham Scan Converting Line Algorithm is used to 
  201. draw lines on the images.  All the triangles are drawn by this line
  202. drawing method.
  203.  
  204. 3. Linear Transformation
  205.  
  206.     When the program starts to morph, the transformation of the
  207. triangles is done by Linear Transformation.  This algorithm provides
  208. an easy way to find the intermediate position of the triangles.
  209.  
  210. 4. Find Points Within Particular Triangles
  211.  
  212.     After finding the intermediate triangles, corresponding 
  213. points of the source, intermediate and target triangles must be 
  214. known in order to find the corresponding color for those points.
  215.  
  216.     A similar approach to the scan converting left edge of a 
  217. polygon described in textbook is used to find out all the points 
  218. within a given triangle.
  219.  
  220. 5. Affine Transformation
  221.  
  222.     After finding the points in each triangles, Affine 
  223. Transformation is used to find its corresponding points in the 
  224. source and target images
  225.  
  226. 6. Finding Color
  227.  
  228.     For each pixels, its color is then calculated from the source 
  229. and target images' color and approximate color is displayed.
  230.  
  231. 7. Program Output
  232.  
  233.     The intermediate steps are shown in the screen.  In addition, all the 
  234. intermediate images would be stored on disk with the user given file
  235. names.  The file format is 320x200 GIF.
  236.  
  237.  
  238.  
  239.  
  240.  
  241.  
  242.  
  243.  
  244.  
  245.  
  246. D. Other Consideration and Limitation
  247.  
  248. 1. Color (8-bit color VS 24-bit color)
  249.  
  250.     Due to the limitation of the memory of DOS, it is difficult to
  251. allocate sufficient memory to store the 24-bit image during program
  252. processing.  Hence, 8-bit 256 color is chosen.
  253.  
  254.  
  255. 2. Performance in Time
  256.  
  257.     After integrating the whole program, system testing began.  We 
  258. found that most of the time is spent in calculating the color of each pixel.  
  259. Since at that time, each pixel is required to scan the whole color palette 
  260. and find the closest color.  That is, each pixel for each image must scan
  261. an 256-sized array.  The performance on this is bad.
  262.  
  263.     Therefore, two methods are employed to solve this problem.  
  264. Firstly, we changed that part of code into assembly language in order to 
  265. make it behave better.  This makes the program run in a much faster.  But 
  266. it is still slow. Then, we change our finding color strategy.  A 32x32x32 
  267. hash table representing 64x64x64 RGB color is created to store the closest 
  268. color index in the palette table at the time of morphing.  In finding the 
  269. 6x6x6-bits color from 5x5x5 bits color,  the least significant bit is ignored.  
  270. This approximate quite good and give a better performance in time.
  271.  
  272. 4. Limitation in Transformation
  273.  
  274.     The transformation is mainly divided into two parts.  The reason 
  275. for this is due to the two different color palette for two different images
  276. and also different triangles formed on the two images.
  277.  
  278.     For the first half of the morphing, the color palette of the source 
  279. images would be used while for the second half, the color palette of the
  280. target images is used.  This makes the output has a visible change in the
  281. color just before and after the switching of the color palette.
  282.  
  283.     Since the positions of the corresponding points for the source and 
  284. target images might different a lot, the triangles formed might be
  285. completely different for two images.  Hence, we cannot just use the
  286. displayed formed of triangles to morph images.  The method is that, for
  287. the first half series, the triangles formed by Delaunay Triangulation of the 
  288. source images is used to morph with the corresponding triangles2 of the
  289. target images.  Similarly, the triangles formed by Delaunay Triangulation
  290. of the target image are used to morph with the corresponding triangles of
  291. the source images.  Due to this reason, if the corresponding points of the
  292. source and target images differ a lot, some intermediate steps might
  293. appear to have some overlapping.
  294.  
  295.  
  296.  
  297.  
  298.  
  299.  
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.  
  309.  
  310.  
  311.  
  312.  
  313.  
  314.  
  315. Bibilography
  316.  
  317. 1.      Wolberg, Georage.  Digital Image Warping.  IEEE Computer Society
  318. Press, 1990.
  319.  
  320. 2.      L. De Floriani and E. Puppo.  An On-line Algorithm for Constrained
  321. Delaunat Triangulation.  CVGIP: Graphical Models And Image Processing,
  322. Vol 54, No. 3, July, pp. 290-300, 1992
  323.  
  324. 3.      Detlef Ruprecht and Heinrich Muller.  Image Warping with Scattered
  325. Data Interpolation Methods.  Forschungbericht Nr. 443. 6 November 1992
  326.  
  327. 4.      Valerie Hall.  Introduction to Morphing.  July, 1992.
  328.  
  329. 5.      Foley, van Dam, Feiner and Hughes.  Computer Graphics: Principles
  330. and Practice. 2nd Edition, Addision Wesley
  331.  
  332.  
  333.  
  334.